package cc.wanforme.st.server.util;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

public class PasswordUtil {
	private static final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(15);
	
	
	public static String encodePassword(String password) {
		//return password;
		return passwordEncoder.encode(password);
	}
	
	public static boolean checkPassword(String raw, String encoded) {
		//String encodedRaw = encodePassword(raw);
		//return Objects.equals(encodedRaw, encoded);
		// 这个方法有点慢
		return passwordEncoder.matches(raw, encoded);
	}
	
	public static void main(String[] args) {
		// $2a$15$EJapYhKpACV83c9FVUl.UutkL27u0WgnFZ4Lxc7AKRaGquAtw99.6
		System.out.println( encodePassword("123") );
	}
	
}
